# Maintainer: Wu Zhenyu <wuzy01@qq.com>

_realname=hyperfine
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.19.0
pkgrel=1
pkgdesc='A command-line benchmarking tool (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/sharkdp/hyperfine'
msys2_references=(
  'purl: pkg:cargo/hyperfine'
)
license=('spdx:MIT OR Apache-2.0')
makedepends=("${MINGW_PACKAGE_PREFIX}-rust")
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('d1c782a54b9ebcdc1dedf8356a25ee11e11099a664a7d9413fdd3742138fa140')

prepare() {
  cd "${_realname}-${pkgver}"

  cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
  cd "${_realname}-${pkgver}"

  cargo build --release --frozen
}

check() {
  cd "${_realname}-${pkgver}"

  cargo test --release --frozen
}

package() {
  cd "${_realname}-${pkgver}"

  install -Dm644 "LICENSE-APACHE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-APACHE"
  install -Dm644 "LICENSE-MIT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE-MIT"
  install -Dm755 "target/release/${_realname}" "${pkgdir}${MINGW_PREFIX}/bin/$_realname"

  install -Dm644 target/release/build/hyperfine-*/out/hyperfine.bash "${pkgdir}${MINGW_PREFIX}/share/bash-completion/completions/hyperfine"
  install -Dm644 target/release/build/hyperfine-*/out/hyperfine.fish "${pkgdir}${MINGW_PREFIX}/share/fish/vendor_completions.d/hyperfine.fish"
  install -Dm644 target/release/build/hyperfine-*/out/_hyperfine "${pkgdir}${MINGW_PREFIX}/share/zsh/site-functions/_hyperfine"

  install -Dm644 doc/hyperfine.1 "${pkgdir}${MINGW_PREFIX}/share/man/man1/hyperfine.1"
}
